<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>我的店铺</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection" content="telephone=no" />
<link href="{$Think.config.RESOURCEURL}wx_assets/css/common.css{$Think.config.RESOURCE_VER}" rel="stylesheet" type="text/css">
<link href="{$Think.config.RESOURCEURL}wx_assets/quan/account.css{$Think.config.RESOURCE_VER}" rel="stylesheet" type="text/css">
<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.1.1.3.min.js{$Think.config.RESOURCE_VER}"></script>
<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.alert.js{$Think.config.RESOURCE_VER}"></script>
<script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="{$Think.config.RESOURCEURL}wx_assets/js/wx_share.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
</head>
<body>
<div class="edit-box" id="editBox">
    <div class="input-box">
        <input type='text' id="inputEdit"/>
        <em id="clearBtn"></em>
    </div>
    <div class="op-box" id="opBox">
        <a class="cancel">取消</a>
        <a class="save">保存</a>
    </div>
</div>
<div class="main" id="homeBox">
    <div class="homebox">
        <dl class="head chooseImage">
            <dd>头像<input type="hidden" value="{$headImgUrl}" id="hid_headImgUrl"/> </dd>
            <dt>
                <div class="headImg">
                    <img src="{$headImgUrl}" id="headImgUrl" onload="$.util.imgCenter(this)" />
                </div>
            </dt>
        </dl>
        <dl>
            <dd>名字<input type="hidden" value="{$nickName}" id="nickName"/> </dd>
            <dt edit="1" required="1" errmsg="名字不能为空!">{$nickName}</dt>
        </dl>
        <dl>
            <dd>微信号<input type="hidden" id="wxId" value="{$wxId}"/></dd>
            <dt edit="1">{$wxId}</dt>
        </dl>
    </div>
    <div class="homebox">
        <dl>
            <dd>个性签名<input type="hidden" id="slogan" value="{$slogan}" maxlength="20" /></dd>
            <dt edit="1" style="height:auto;min-height:40px;line-height:28px;">{$slogan}</dt>
        </dl>
        <dl class="remove chooseImage themeImg">
            <dd>更换背景<input type="hidden" value="{$themeImgUrl}" id="hid_themeImgUrl"/></dd>
            <dt class="themeImg" style="height:auto;min-height:40px;padding:10px 0">
                <if condition="$themeImgUrl neq ''">
                    <img src="{$themeImgUrl}" id="themeImg" style="max-width:320px;max-height:50px" />
                    <else/>
                    <img src="{$Think.config.RESOURCEURL}wx_assets/quan/img/shopindexbg.png" id="themeImg" style="max-width:320px;max-height:50px" />
                </if>
            </dt>
        </dl>
    </div>
    <div class="homebox button">
        <a href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&module=quan&method=shopIndex&params=%7B"qId"%3A"{$qId}"%7D'>返回</a>
    </div>
</div>
<script>
    var baseUrl = '{$Think.config.SERVER_HOST}';
    var userName='{$userName}';
	var home={
        init:function(){
            //this._initValidate();
            this._initEvent();
        },
        _initEvent:function(){
            var me=this;
            $("#homeBox dl").click(function(){
                var dl=$(this);
                if(!$(this).hasClass("chooseImage")){
                    var dt=$(this).find("dt");
                   if(dt.attr("edit")){
                        dt.addClass("active");
                        $("#inputEdit").val(dt.text());
                        $("#editBox").css("height",$(window).height()).show();
                   }
                }else {
                    wx_share.uploadImage(function(data){
                        if(dl.hasClass("head")){
                            $("#headImgUrl").attr("src",data.path+"@56w_56h_1e_1c_2o_1sh.jpg");
                            $("#hid_headImgUrl").val(data.path+"@56w_56h_1e_1c_2o_1sh.jpg");
                        } else{
                            var winW=$.util.page.getViewWidth();
                            $("#themeImg").attr("src",data.path+"@"+winW+"w_130h_1e_1c_2o_1sh.jpg");
                            $("#hid_themeImgUrl").val(data.path+"@"+winW+"w_130h_1e_1c_2o_1sh.jpg"); 
                        }
                        $("#inputEdit").val(data.path);
                        me._save();
                    });
                }
            });
            $("#opBox .cancel").click(function(){
                $("#homeBox dt.active").removeClass("active");
                $("#editBox").hide();
            });
            $("#opBox .save").click(function(){
                me._save();
            });
            $("#clearBtn").click(function(){
                $("#inputEdit").val("");
            });
        },
        _save:function(){
            var v=$("#inputEdit").val();
            var active=$("#homeBox dt.active");
            if(active.attr("required") && !v){
                $.util.alert(active.attr("errmsg"));
                return false;
            }
            if(v){
                $("#homeBox dt.active").text(v);
                $("#homeBox dt.active").parent().find("input").val(v); 
                $.req.get("call.json?module=quan&customerId={$customerId}&method=saveUser",{
                    userName:"{$userName}",
                    params:{
                        "nickName":$("#nickName").val(),
                        "headImgUrl":$("#hid_headImgUrl").val(),
                        "themeImgUrl":$("#hid_themeImgUrl").val(),
                        "wxId":$("#wxId").val(),
                        "slogan":$("#slogan").val(),
                        "qId":"{$qId}"
                    }
                },function(data){
                    if(!data.code){
                        $("#homeBox dt.active").removeClass("active");
                        $("#editBox").hide();
                    }
                });
            }
        },
        getShareUrl:function(){
            var p=$.util.getParamAsObject();
            var shareUrl="";
            var params={
                "qId":"{$qId}",
                "fromUId":"{$fromUId}"
            };
            params=encodeURIComponent(JSON.stringify(params));
            shareUrl=baseUrl+'call.html?customerId={$customerId}&module=quan&scope=1&method=shopIndex&params='+params;
            return shareUrl;
        }
    }
    home.init();
    var shareUrl=home.getShareUrl();
    wx_share.init({
        "title":"{$nickName}的密友圈",
        "desc":'{$slogan}',
        "link":shareUrl,
        "imgUrl":"{$headImgUrl}",
        "pkg":{
            "appId": '{$pkg.appId}',
            "timestamp": {$pkg.timestamp},
            "nonceStr": '{$pkg.nonceStr}',
            "signature": '{$pkg.signature}'
        },
        success:function(config,shareType){
            
        }
    });
</script>
</body>
</html>